Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtMin As System.Windows.Forms.TextBox Friend WithEvents TxtMiles As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtSpeedLimit As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox Friend WithEvents TxtSpeed As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents TxtSpeedLimitOut As System.Windows.Forms.TextBox Friend WithEvents TxtFine As System.Windows.Forms.TextBox Friend WithEvents BtnSubmit As System.Windows.Forms.Button Friend WithEvents BtnClear As System.Windows.Forms.Button Friend WithEvents TxtNumScanned As System.Windows.Forms.TextBox Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents TxtNumSpeeding As System.Windows.Forms.TextBox Friend WithEvents Label9 As System.Windows.Forms.Label Friend WithEvents TxtPctSpeeding As System.Windows.Forms.TextBox Friend WithEvents Label10 As System.Windows.Forms.Label Friend WithEvents TxtTotFines As System.Windows.Forms.TextBox Friend WithEvents Label11 As System.Windows.Forms.Label Friend WithEvents TxtAveFine As System.Windows.Forms.TextBox Friend WithEvents Label12 As System.Windows.Forms.Label Friend WithEvents TxtAveSpeedingFine As System.Windows.Forms.TextBox Friend WithEvents Label13 As System.Windows.Forms.Label Friend WithEvents TxtAveSpeed As System.Windows.Forms.TextBox Friend WithEvents Label15 As System.Windows.Forms.Label Friend WithEvents BtnRestart As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents GrpBilling As System.Windows.Forms.GroupBox Friend WithEvents LblSpeedLimitOut As System.Windows.Forms.Label Friend WithEvents LblFine As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.GroupBox1 = New System.Windows.Forms.GroupBox Me.Label2 = New System.Windows.Forms.Label Me.TxtMin = New System.Windows.Forms.TextBox Me.TxtMiles = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.TxtSpeedLimit = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.GrpBilling = New System.Windows.Forms.GroupBox Me.GroupBox3 = New System.Windows.Forms.GroupBox Me.TxtSpeed = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtSpeedLimitOut = New System.Windows.Forms.TextBox Me.LblSpeedLimitOut = New System.Windows.Forms.Label Me.TxtFine = New System.Windows.Forms.TextBox Me.LblFine = New System.Windows.Forms.Label Me.BtnSubmit = New System.Windows.Forms.Button Me.BtnClear = New System.Windows.Forms.Button Me.TxtNumScanned = New System.Windows.Forms.TextBox Me.Label8 = New System.Windows.Forms.Label Me.TxtNumSpeeding = New System.Windows.Forms.TextBox Me.Label9 = New System.Windows.Forms.Label Me.TxtPctSpeeding = New System.Windows.Forms.TextBox Me.Label10 = New System.Windows.Forms.Label Me.TxtTotFines = New System.Windows.Forms.TextBox Me.Label11 = New System.Windows.Forms.Label Me.TxtAveFine = New System.Windows.Forms.TextBox Me.Label12 = New System.Windows.Forms.Label Me.TxtAveSpeedingFine = New System.Windows.Forms.TextBox Me.Label13 = New System.Windows.Forms.Label Me.TxtAveSpeed = New System.Windows.Forms.TextBox Me.Label15 = New System.Windows.Forms.Label Me.BtnRestart = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.GroupBox1.SuspendLayout() Me.GrpBilling.SuspendLayout() Me.GroupBox3.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(216, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(592, 56) Me.Label1.TabIndex = 0 Me.Label1.Text = "Garden State Parkway" ' 'GroupBox1 ' Me.GroupBox1.Controls.Add(Me.BtnClear) Me.GroupBox1.Controls.Add(Me.BtnSubmit) Me.GroupBox1.Controls.Add(Me.TxtSpeedLimit) Me.GroupBox1.Controls.Add(Me.Label4) Me.GroupBox1.Controls.Add(Me.TxtMiles) Me.GroupBox1.Controls.Add(Me.Label3) Me.GroupBox1.Controls.Add(Me.TxtMin) Me.GroupBox1.Controls.Add(Me.Label2) Me.GroupBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.GroupBox1.Location = New System.Drawing.Point(40, 96) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(344, 240) Me.GroupBox1.TabIndex = 1 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "Current Scanned Pass" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(24, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(168, 32) Me.Label2.TabIndex = 0 Me.Label2.Text = "Time Elapsed (Min):" ' 'TxtMin ' Me.TxtMin.Location = New System.Drawing.Point(216, 48) Me.TxtMin.Name = "TxtMin" Me.TxtMin.Size = New System.Drawing.Size(112, 24) Me.TxtMin.TabIndex = 1 Me.TxtMin.Text = "" ' 'TxtMiles ' Me.TxtMiles.Location = New System.Drawing.Point(216, 96) Me.TxtMiles.Name = "TxtMiles" Me.TxtMiles.Size = New System.Drawing.Size(112, 24) Me.TxtMiles.TabIndex = 3 Me.TxtMiles.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(24, 96) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(168, 32) Me.Label3.TabIndex = 2 Me.Label3.Text = "Miles Traveled:" ' 'TxtSpeedLimit ' Me.TxtSpeedLimit.Location = New System.Drawing.Point(216, 152) Me.TxtSpeedLimit.Name = "TxtSpeedLimit" Me.TxtSpeedLimit.Size = New System.Drawing.Size(112, 24) Me.TxtSpeedLimit.TabIndex = 5 Me.TxtSpeedLimit.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(24, 152) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(168, 32) Me.Label4.TabIndex = 4 Me.Label4.Text = "Speed Limit:" ' 'GrpBilling ' Me.GrpBilling.Controls.Add(Me.TxtFine) Me.GrpBilling.Controls.Add(Me.LblFine) Me.GrpBilling.Controls.Add(Me.TxtSpeedLimitOut) Me.GrpBilling.Controls.Add(Me.LblSpeedLimitOut) Me.GrpBilling.Controls.Add(Me.TxtSpeed) Me.GrpBilling.Controls.Add(Me.Label5) Me.GrpBilling.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.GrpBilling.Location = New System.Drawing.Point(40, 360) Me.GrpBilling.Name = "GrpBilling" Me.GrpBilling.Size = New System.Drawing.Size(344, 216) Me.GrpBilling.TabIndex = 2 Me.GrpBilling.TabStop = False Me.GrpBilling.Text = "Billing Info" ' 'GroupBox3 ' Me.GroupBox3.Controls.Add(Me.TxtAveSpeed) Me.GroupBox3.Controls.Add(Me.Label15) Me.GroupBox3.Controls.Add(Me.TxtAveSpeedingFine) Me.GroupBox3.Controls.Add(Me.Label13) Me.GroupBox3.Controls.Add(Me.TxtAveFine) Me.GroupBox3.Controls.Add(Me.Label12) Me.GroupBox3.Controls.Add(Me.TxtTotFines) Me.GroupBox3.Controls.Add(Me.Label11) Me.GroupBox3.Controls.Add(Me.TxtPctSpeeding) Me.GroupBox3.Controls.Add(Me.Label10) Me.GroupBox3.Controls.Add(Me.TxtNumSpeeding) Me.GroupBox3.Controls.Add(Me.Label9) Me.GroupBox3.Controls.Add(Me.TxtNumScanned) Me.GroupBox3.Controls.Add(Me.Label8) Me.GroupBox3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.GroupBox3.Location = New System.Drawing.Point(456, 104) Me.GroupBox3.Name = "GroupBox3" Me.GroupBox3.Size = New System.Drawing.Size(408, 336) Me.GroupBox3.TabIndex = 3 Me.GroupBox3.TabStop = False Me.GroupBox3.Text = "Summary Statistics" ' 'TxtSpeed ' Me.TxtSpeed.Location = New System.Drawing.Point(208, 40) Me.TxtSpeed.Name = "TxtSpeed" Me.TxtSpeed.ReadOnly = True Me.TxtSpeed.Size = New System.Drawing.Size(112, 24) Me.TxtSpeed.TabIndex = 3 Me.TxtSpeed.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(20, 40) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(168, 32) Me.Label5.TabIndex = 2 Me.Label5.Text = "Average Speed:" ' 'TxtSpeedLimitOut ' Me.TxtSpeedLimitOut.Location = New System.Drawing.Point(208, 92) Me.TxtSpeedLimitOut.Name = "TxtSpeedLimitOut" Me.TxtSpeedLimitOut.ReadOnly = True Me.TxtSpeedLimitOut.Size = New System.Drawing.Size(112, 24) Me.TxtSpeedLimitOut.TabIndex = 5 Me.TxtSpeedLimitOut.Text = "" ' 'LblSpeedLimitOut ' Me.LblSpeedLimitOut.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblSpeedLimitOut.Location = New System.Drawing.Point(20, 92) Me.LblSpeedLimitOut.Name = "LblSpeedLimitOut" Me.LblSpeedLimitOut.Size = New System.Drawing.Size(168, 32) Me.LblSpeedLimitOut.TabIndex = 4 Me.LblSpeedLimitOut.Text = "Speed Limit:" ' 'TxtFine ' Me.TxtFine.Location = New System.Drawing.Point(208, 152) Me.TxtFine.Name = "TxtFine" Me.TxtFine.ReadOnly = True Me.TxtFine.Size = New System.Drawing.Size(112, 24) Me.TxtFine.TabIndex = 7 Me.TxtFine.Text = "" ' 'LblFine ' Me.LblFine.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblFine.Location = New System.Drawing.Point(20, 152) Me.LblFine.Name = "LblFine" Me.LblFine.Size = New System.Drawing.Size(168, 32) Me.LblFine.TabIndex = 6 Me.LblFine.Text = "Fine:" ' 'BtnSubmit ' Me.BtnSubmit.Location = New System.Drawing.Point(40, 192) Me.BtnSubmit.Name = "BtnSubmit" Me.BtnSubmit.Size = New System.Drawing.Size(104, 32) Me.BtnSubmit.TabIndex = 6 Me.BtnSubmit.Text = "Submit" ' 'BtnClear ' Me.BtnClear.Location = New System.Drawing.Point(168, 192) Me.BtnClear.Name = "BtnClear" Me.BtnClear.Size = New System.Drawing.Size(104, 32) Me.BtnClear.TabIndex = 7 Me.BtnClear.Text = "Clear" ' 'TxtNumScanned ' Me.TxtNumScanned.Location = New System.Drawing.Point(280, 40) Me.TxtNumScanned.Name = "TxtNumScanned" Me.TxtNumScanned.ReadOnly = True Me.TxtNumScanned.Size = New System.Drawing.Size(96, 24) Me.TxtNumScanned.TabIndex = 5 Me.TxtNumScanned.Text = "0" ' 'Label8 ' Me.Label8.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label8.Location = New System.Drawing.Point(16, 40) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(208, 32) Me.Label8.TabIndex = 4 Me.Label8.Text = "Number of Cars Scanned:" ' 'TxtNumSpeeding ' Me.TxtNumSpeeding.Location = New System.Drawing.Point(280, 80) Me.TxtNumSpeeding.Name = "TxtNumSpeeding" Me.TxtNumSpeeding.ReadOnly = True Me.TxtNumSpeeding.Size = New System.Drawing.Size(96, 24) Me.TxtNumSpeeding.TabIndex = 7 Me.TxtNumSpeeding.Text = "0" ' 'Label9 ' Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label9.Location = New System.Drawing.Point(16, 80) Me.Label9.Name = "Label9" Me.Label9.Size = New System.Drawing.Size(216, 32) Me.Label9.TabIndex = 6 Me.Label9.Text = "Number of Cars Speeding:" ' 'TxtPctSpeeding ' Me.TxtPctSpeeding.Location = New System.Drawing.Point(280, 120) Me.TxtPctSpeeding.Name = "TxtPctSpeeding" Me.TxtPctSpeeding.ReadOnly = True Me.TxtPctSpeeding.Size = New System.Drawing.Size(96, 24) Me.TxtPctSpeeding.TabIndex = 9 Me.TxtPctSpeeding.Text = "0" ' 'Label10 ' Me.Label10.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label10.Location = New System.Drawing.Point(16, 120) Me.Label10.Name = "Label10" Me.Label10.Size = New System.Drawing.Size(216, 32) Me.Label10.TabIndex = 8 Me.Label10.Text = "Percent of Cars Speeding:" ' 'TxtTotFines ' Me.TxtTotFines.Location = New System.Drawing.Point(280, 200) Me.TxtTotFines.Name = "TxtTotFines" Me.TxtTotFines.ReadOnly = True Me.TxtTotFines.Size = New System.Drawing.Size(96, 24) Me.TxtTotFines.TabIndex = 11 Me.TxtTotFines.Text = "0" ' 'Label11 ' Me.Label11.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label11.Location = New System.Drawing.Point(16, 200) Me.Label11.Name = "Label11" Me.Label11.Size = New System.Drawing.Size(216, 32) Me.Label11.TabIndex = 10 Me.Label11.Text = "Total Fines:" ' 'TxtAveFine ' Me.TxtAveFine.Location = New System.Drawing.Point(280, 240) Me.TxtAveFine.Name = "TxtAveFine" Me.TxtAveFine.ReadOnly = True Me.TxtAveFine.Size = New System.Drawing.Size(96, 24) Me.TxtAveFine.TabIndex = 13 Me.TxtAveFine.Text = "0" ' 'Label12 ' Me.Label12.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label12.Location = New System.Drawing.Point(16, 240) Me.Label12.Name = "Label12" Me.Label12.Size = New System.Drawing.Size(216, 32) Me.Label12.TabIndex = 12 Me.Label12.Text = "Average Fine Per Car:" ' 'TxtAveSpeedingFine ' Me.TxtAveSpeedingFine.Location = New System.Drawing.Point(280, 280) Me.TxtAveSpeedingFine.Name = "TxtAveSpeedingFine" Me.TxtAveSpeedingFine.ReadOnly = True Me.TxtAveSpeedingFine.Size = New System.Drawing.Size(96, 24) Me.TxtAveSpeedingFine.TabIndex = 15 Me.TxtAveSpeedingFine.Text = "0" ' 'Label13 ' Me.Label13.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label13.Location = New System.Drawing.Point(16, 280) Me.Label13.Name = "Label13" Me.Label13.Size = New System.Drawing.Size(264, 32) Me.Label13.TabIndex = 14 Me.Label13.Text = "Average Fine Per Speeding Car:" ' 'TxtAveSpeed ' Me.TxtAveSpeed.Location = New System.Drawing.Point(280, 160) Me.TxtAveSpeed.Name = "TxtAveSpeed" Me.TxtAveSpeed.ReadOnly = True Me.TxtAveSpeed.Size = New System.Drawing.Size(96, 24) Me.TxtAveSpeed.TabIndex = 19 Me.TxtAveSpeed.Text = "0" ' 'Label15 ' Me.Label15.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label15.Location = New System.Drawing.Point(16, 160) Me.Label15.Name = "Label15" Me.Label15.Size = New System.Drawing.Size(216, 32) Me.Label15.TabIndex = 18 Me.Label15.Text = "Average Speed:" ' 'BtnRestart ' Me.BtnRestart.Location = New System.Drawing.Point(520, 480) Me.BtnRestart.Name = "BtnRestart" Me.BtnRestart.Size = New System.Drawing.Size(104, 32) Me.BtnRestart.TabIndex = 8 Me.BtnRestart.Text = "Re-Start" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(648, 480) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(104, 32) Me.BtnQuit.TabIndex = 9 Me.BtnQuit.Text = "Quit" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(880, 608) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.BtnRestart) Me.Controls.Add(Me.GroupBox3) Me.Controls.Add(Me.GrpBilling) Me.Controls.Add(Me.GroupBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Garden State Parkway" Me.GroupBox1.ResumeLayout(False) Me.GrpBilling.ResumeLayout(False) Me.GroupBox3.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Dim totalSpeed As Double = 0 ' symbolic consts for validation Const minLimit As Integer = 35 Const maxLimit As Integer = 70 Const minMiles As Double = 0.1 Const minMinutes As Double = 0.1 Private Function getValidSpeedLimit(ByRef limit As Integer) As Boolean Dim ok As Boolean = True If IsNumeric(TxtSpeedLimit.Text) Then ' data is numeric - covert limit = Convert.ToInt32(TxtSpeedLimit.Text) If limit < minLimit Or limit > maxLimit Then ' bad data MsgBox("Speed Limit must be between " & minLimit & " and " & maxLimit) ok = False End If Else MsgBox("Speed Limit must be numeric") ok = False End If Return ok End Function Private Function getValidMiles(ByRef miles As Double) As Boolean Dim ok As Boolean = True If IsNumeric(TxtMiles.Text) Then ' data is numeric - convert miles = Convert.ToDouble(TxtMiles.Text) If miles < minMiles Then ' no upper limit - though could use whole state as upper ' bad data MsgBox("Number of miles must be at least " & minMiles) ok = False End If Else MsgBox("Number of miles must be numeric") ok = False End If Return ok End Function Private Function getValidMinutes(ByRef minutes As Double) As Boolean Dim ok As Boolean = True If IsNumeric(TxtMin.Text) Then ' data is numeric - convert minutes = Convert.ToDouble(TxtMin.Text) If minutes < minMinutes Then ' no upper limit - though could use whole state as upper ' bad data MsgBox("Number of minutes must be at least " & minMinutes) ok = False End If Else MsgBox("Number of minutes must be numeric") ok = False End If Return ok End Function Private Function getValidInput(ByRef limit As Integer, ByRef miles As Double, ByRef minutes As Double) As Boolean Dim okLimit As Boolean Dim okMiles As Boolean Dim okMin As Boolean okLimit = getValidSpeedLimit(limit) okMiles = getValidMiles(miles) okMin = getValidMinutes(minutes) If okLimit And okMiles And okMin Then Return True Else Return False End If End Function ' calculate miles per hour, given miles and minutes ' Precond: assumes minutes > 0 (and miles > 0) Private Function calcMPH(ByVal mil As Double, ByVal min As Double) As Double Const minPerHour As Integer = 60 Dim speed As Double speed = (mil / min) * minPerHour Return speed End Function Private Function calcFine(ByVal mph As Double, ByVal speedLimit As Integer) As Double Dim overLimit As Double Dim fine As Double If mph <= speedLimit Then fine = 0 Else ' must be over speed limit overLimit = mph - speedLimit If overLimit <= 5.0001 Then fine = 20 ElseIf overLimit <= 10.0001 Then fine = 20 + (2 * overLimit) ElseIf overLimit <= 20.0001 Then fine = 20 + (4 * overLimit) Else fine = 50 + (5 * overLimit) End If ' fine is doubled if the speed limit is 65 or above If speedLimit >= 64.9999 Then fine = fine * 2 End If End If Return fine End Function Private Sub incrCars() Dim cars As Integer cars = Convert.ToInt32(TxtNumScanned.Text) cars = cars + 1 TxtNumScanned.Text = cars.ToString("n0") End Sub Private Sub incrSpeeding() Dim speeding As Integer speeding = Convert.ToInt32(TxtNumSpeeding.Text) speeding = speeding + 1 TxtNumSpeeding.Text = speeding.ToString("n0") End Sub Private Sub updatePct() Dim cars As Integer Dim speeding As Integer Dim pct As Double speeding = Convert.ToInt32(TxtNumSpeeding.Text) cars = Convert.ToInt32(TxtNumScanned.Text) pct = speeding / cars TxtPctSpeeding.Text = pct.ToString("p2") End Sub Private Sub updateAveSpeed(ByVal total As Double) Dim cars As Integer Dim aveSpeed As Double cars = Convert.ToInt32(TxtNumScanned.Text) aveSpeed = total / cars TxtAveSpeed.Text = aveSpeed.ToString("n2") End Sub Private Sub updateTotalFine(ByVal fine As Double) Dim total As Double total = Convert.ToDouble(TxtTotFines.Text.Trim("$"c)) total = total + fine TxtTotFines.Text = total.ToString("c2") End Sub Private Sub updateAveFine() Dim cars As Integer Dim fines As Double Dim ave As Double fines = Convert.ToDouble(TxtTotFines.Text.Trim("$"c)) cars = Convert.ToInt32(TxtNumScanned.Text) ave = fines / cars TxtAveFine.Text = ave.ToString("c2") End Sub Private Sub updateAveSpeedingFine() Dim speedingCars As Integer Dim fines As Double Dim ave As Double fines = Convert.ToDouble(TxtTotFines.Text.Trim("$"c)) speedingCars = Convert.ToInt32(TxtNumSpeeding.Text) ' avoid divide by zero error If speedingCars > 0 Then ave = fines / speedingCars Else ave = 0 End If TxtAveSpeedingFine.Text = ave.ToString("c2") End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click TxtMin.Text = "" TxtMiles.Text = "" TxtSpeedLimit.Text = "" End Sub Private Sub BtnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRestart.Click TxtMin.Text = "" TxtMiles.Text = "" TxtSpeedLimit.Text = "" GrpBilling.Visible = False TxtSpeedLimitOut.Text = "" TxtSpeed.Text = "" TxtFine.Text = "" TxtNumScanned.Text = "0" TxtNumSpeeding.Text = "0" TxtPctSpeeding.Text = "0" TxtTotFines.Text = "0" TxtAveFine.Text = "0" TxtAveSpeed.Text = "0" TxtAveSpeedingFine.Text = "0" ' reset global vars totalSpeed = 0 End Sub Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click Dim inputOk As Boolean Dim limit As Integer Dim time As Double Dim distance As Double Dim Fine As Double Dim speed As Double inputOk = getValidInput(limit, distance, time) If inputOk Then speed = calcMPH(distance, time) totalSpeed = totalSpeed + speed ' update so available for average Fine = calcFine(speed, limit) ' display results TxtSpeed.Text = speed.ToString("n1") TxtSpeedLimitOut.Text = TxtSpeedLimit.Text TxtFine.Text = Fine.ToString("c") GrpBilling.Visible = True ' update totals incrCars() ' some things only get done if there is a fine If Fine > 0.0001 Then ' actually show the fine TxtFine.Visible = True LblFine.Visible = True TxtSpeedLimitOut.Visible = True LblSpeedLimitOut.Visible = True incrSpeeding() updateTotalFine(Fine) Else ' hide the fine TxtFine.Visible = False LblFine.Visible = False TxtSpeedLimitOut.Visible = False LblSpeedLimitOut.Visible = False End If updatePct() ' update percent speeding updateAveSpeed(totalSpeed) updateAveFine() updateAveSpeedingFine() End If End Sub End Class